/// <reference path="./declare.ts"/>

import { PermissionConfig, WebsiteConfig, } from "maishu-chitu-admin";
import { merchantRoleId } from "../merchant";
import { roleIds } from "maishu-node-auth";
export let stationPath = "/shop/";
export let componetsDirectory = "components";

let contextName = stationPath;

//============================================================================================
// 站点访问权限
export let permissions: PermissionConfig = {}
permissions[`${stationPath}*`] = { roleIds: [merchantRoleId] };
permissions[`${stationPath}mobile*`] = { roleIds: [roleIds.anonymous] };
// permissions[`/${stationPath}/*`] = { roleIds: [adminRoleId] };
//============================================================================================

export let menuItemIds = {
    setting: "4C715313-F1D2-4F7B-8C91-B3C904A2DEF0",
    user: "AD03726E-DEA4-40EF-8017-8DCF56956F4F",
}

export interface ServerContextData {
    gateway: string
}


let lib = "./lib";
export default function (data: ServerContextData) {
    let websiteConfig: WebsiteConfig & ShopWebsiteConfig = {
        serviceHost: data.gateway,
        stationPath,
        contextName,
        componetsDirectory,
        defaultAppKey: "7bbfa36c-8115-47ad-8d47-9e52b58e7efd",
        requirejs: {
            context: contextName,
            shim: {
                "bootstrap-datepicker": {
                    deps: [
                        `css!${lib}/bootstrap-datepicker/css/bootstrap-datepicker`
                    ]
                }
            },
            paths: {
                "ace_editor": `${lib}/ace-builds/src`,
                "clipboard": `${lib}/clipboard.min`,
                "devices": `${lib}/devices.css-1.2/assets/devices.min`,
                "jquery-ui": `${lib}/jquery-ui-1.12.1/jquery-ui`,
                "js-xlsx": `${lib}/js-xlsx/xlsx.full.min`,
                "qrcode": `${lib}/qrcode`,
                "ue": `${lib}/ueditor`,

                "maishu-jueying": "/node_modules/maishu-jueying/dist/index",
                "bootstrap-datepicker": `${lib}/bootstrap-datepicker/js/bootstrap-datepicker`,
                'components': `./components/`,
            }
        },
        menuItems: [
            {
                id: "76D932F6-FF4B-4F1A-AB4F-704B5F07732D", name: "微店", icon: "icon-dashboard",
                sortNumber: 100,
                children: [
                    { id: "A922A210-D964-4A73-89D9-5F9D3F32BE53", name: "店铺设置", path: "#store/setting" },
                    { id: "D74FEC40-31AC-4498-A28F-A82472265831", name: "店铺首页", path: "#store/home" },
                    { id: "EEEF566A-9E54-4C7C-BD3D-148785ADCF94", name: "会员主页", path: "#store/member" },
                    { id: "D49C505B-BD7D-4D07-9992-265CD15EE0A2", name: "店铺导航", path: "#store/menu" },
                    { id: "661B2D96-5C97-4EBC-A6DB-952BAA642E7E", name: "购物车", path: "#store/shoppingCart" },
                    { id: "ED163BA7-3674-46DE-B36A-4F09974FABEE", name: "店铺风格", path: "#store/style" },
                    { id: "717122F5-3EA0-42E8-9412-3F0376F604C1", name: "商品类别", path: "#store/categories" }
                ]
            },
            {
                id: "02AFF1E9-82E2-46E1-89B2-A634C2A32F3B", name: "商品", icon: "icon-gift",
                sortNumber: 200,
                children: [
                    {
                        id: "4F1F1120-1BBF-4DAB-BDFB-1257A1857028", name: "商品列表", path: "#shopping/product-list", children: [
                            { id: "DBFECC6D-23EB-401A-A11C-0A1AABBE3B08", name: "", path: "#shopping/product-add" },
                            { id: "EFA6F80A-9D08-468A-857C-12F57CCB79A1", name: "", path: "#shopping/product-edit" }
                        ],
                    },
                    { id: "EFA6F80A-9D08-468A-857C-12F57CCB79A1", name: "商品品牌", path: "#shopping/brand-list" }
                ]
            },
            {
                id: "F3353D09-646F-4740-A93A-A298B11ACBE6", name: "订单", icon: "icon-list",
                sortNumber: 300,
                children: [
                    { id: "06E53097-350A-428A-8D3B-7BECA8916F82", name: "订单列表", path: "#shopping/order-list" }
                ]
            },
            {
                id: "EE09A61C-6679-41CE-A20C-2977FE23AA3B", name: "营销", icon: "icon-bullhorn",
                sortNumber: 400,
                children: [
                    {
                        id: "4A8B6721-6396-49E2-A909-D7C79747A29F", name: "促销活动", path: "#shopping/promotion/activities", children: [
                            { id: "391E681D-DD31-4700-B6C5-3C1D20E38BE1", name: "", path: "#shopping/promotion/activityEdit" }
                        ]
                    },
                    { id: "D6ABC890-369A-40BB-B05B-CA2EB61E9A38", name: "优惠券", path: "#coupon/coupon-list", children: [] },
                    { id: "1879473C-350C-4ABA-BF2F-A508C6698D47", name: "优惠码", path: "#coupon/coupon-code-list", children: [] }
                ]
            },
            {
                id: menuItemIds.user, icon: "icon-cog", name: "用户",
                sortNumber: 450,
                children: []
            },
            {
                id: menuItemIds.setting, name: "设置", icon: "icon-cog",
                sortNumber: 500,
                children: [
                    // { id: "B75CFD3D-AFDD-45A8-83F6-75A344E0836F", name: "微信设置", path: "#settings/weixin", sortNumber: 100 },
                    {
                        id: "1E462D34-BB77-412E-8645-12A4BF81999E", name: "运费设置", path: "#freight/solution-list", sortNumber: 200,
                        children: [
                            { id: "4647513A-513E-45F0-A5AE-CD6FE4B7C5B7", name: "", path: "#freight/freight-list" }
                        ]
                    }
                ]
            }
        ]
    }

    let stack = [...websiteConfig.menuItems];
    while (stack.length > 0) {
        let item = stack.shift();
        item.roleIds = [merchantRoleId];
        (item.children || []).forEach(child => {
            stack.unshift(child);
        })
    }

    return websiteConfig;

}